package com.kc.gb.device.controller;

import com.kc.gb.base.dto.Result;
import com.kc.gb.device.common.properties.DeviceProperties;
import com.kc.gb.device.controller.dto.PtlLightStateQuery;
import com.kc.gb.device.plugins.ptl.service.PtlHardwareService;
import com.kc.gb.device.service.WallPtlAdminService;
import com.kc.gb.device.service.support.dto.StationSlotArea;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/device/wall-ptl")
public class WallPtlAdminController {

    @Resource
    DeviceProperties deviceProperties;

    @Resource
    PtlHardwareService devicePtlService;

    @Resource
    WallPtlAdminService iWallPtlAdminService;

    @GetMapping(path = "/layouts")
    private Result<?> getStationByDeviceCode(@RequestParam String stationCode) {
        try {
            List<StationSlotArea> areas = iWallPtlAdminService.getStationWallLights(deviceProperties.getWarehouseId(),stationCode);
            return Result.success(areas);
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/states")
    Result<?> states(@RequestBody PtlLightStateQuery query){
        return Result.success(devicePtlService.getLightStates(query.isDebug(), query.getLightNos()));
    }

    @GetMapping("/press")
    Result<?> press(boolean inDebugMode,int lightNo){
        iWallPtlAdminService.press(inDebugMode,lightNo);
        return Result.success();
    }

    @GetMapping("/getMode")
    Result<?> getMode(){
        boolean result = iWallPtlAdminService.getMode();
        return Result.success(result);
    }

    @GetMapping("/setMode")
    Result<?> setMode(boolean inDebugMode){
        boolean finalMode = iWallPtlAdminService.changeMode(inDebugMode);
        return Result.success(finalMode);
    }
}
